package cool.taomu.software.fig.core.test;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import cool.taomu.software.fig.core.CreateMqttClient;
import cool.taomu.software.fig.mqtt.client.paho.MQTTSender;
import cool.taomu.software.fig.mqtt.client.paho.MQTTSubscriber;
import cool.taomu.software.fig.mqtt.client.paho.entity.SenderEntity;

public class SubMain {

	public static void main(String[] args) throws InterruptedException {
		ExecutorService exec = Executors.newCachedThreadPool(new ThreadFactory() {
			public Thread newThread(Runnable r) {
				return new Thread(r);
			}
		});
		CreateMqttClient client = new CreateMqttClient();
		List<MQTTSubscriber> subs = client.create(TestSubscriber.class);
		subs.forEach(it -> exec.submit(it));
		TimeUnit.SECONDS.sleep(5);
		MQTTSender sender = new MQTTSender();
		sender.publish(new SenderEntity("start").ip("127.0.0.1").port(1883).username("admin").password("123456")
				.message("Hello Start"));
	}

}
